
import {useState} from 'react'

export const useAlarmsPopup = (initData,okCallback = () => {}, cancelCallback = () => {}) => {

  const [data, setData] = useState(initData)

  return [data,{
    onRadioClick : (id, checked) => {
      if(!data[id]){
        data[id] = {}
      }
      data[id].result = checked ? 'C' : 'N'
      console.log('data',data)
    },
    onTextAreaChange: (id, text) => {
      if(!data[id]){
        data[id] = {}
      }
      data[id].handle_remark = text
      console.log('data',data)
    },
    onCancel: () => {
      setData(pre => {
        cancelCallback(pre)
        return {}
      })

    },
    onOk:() => {
      setData(pre => {
        okCallback(pre)
        return {}
      })
    },
    setPopupData: (nextData) => {
      setData(nextData)
    }
  }]
}